local bixian = fk.CreateSkill{
  name = "hanqing__bixian",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__bixian"] = "匕现",
  [":hanqing__bixian"] = "锁定技，结束阶段，若你没有未明置的手牌，你弃置所有手牌，视为对一名其他角色使用等量张【杀】（有距离限制）。",

  ["#hanqing__bixian-invoke"] = "匕现：视为对一名角色使用%arg张【杀】！",
}

local DIY = require "packages/diy_utility/diy_utility"

bixian:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(bixian.name) and player.phase == Player.Finish and
      not player:isKongcheng() and player:getHandcardNum() == #DIY.getShownCards(player)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = #table.filter(player:getCardIds("h"), function (id)
      return not player:prohibitDiscard(id)
    end)
    player:throwAllCards("h", bixian.name)
    if n == 0 or player.dead then return end
    local targets = table.filter(room:getOtherPlayers(player, false), function (p)
      return player:canUseTo(Fk:cloneCard("slash"), p, { bypass_times = true })
    end)
    if #targets == 0 then return end
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = bixian.name,
      prompt = "#hanqing__bixian-invoke:::"..n,
      cancelable = false,
    })[1]
    for _ = 1, n do
      if player.dead or to.dead then return end
      room:delay(800)
      room:useVirtualCard("slash", nil, player, to, bixian.name, true)
    end
  end,
})

return bixian
